package beego

import (
	beego "github.com/beego/beego/v2/server/web"
	beeContext "github.com/beego/beego/v2/server/web/context"
)

type BeeCtx = beeContext.Context
type BeeNextFunc = beego.FilterFunc
type FilterFunc func(next beego.FilterFunc) beego.FilterFunc

type BeeFilter struct {
	Pattern    string
	FilterFunc FilterFunc
}

func InsertFilterChain(pattern string, defFunc func(ctx *BeeCtx, next BeeNextFunc)) {
	beego.InsertFilterChain(pattern, func(next beego.FilterFunc) beego.FilterFunc {
		return func(ctx *beeContext.Context) {
			defFunc(ctx, next)
		}
	})
}
func InsertGlobalFilterChain(defFunc func(ctx *BeeCtx, next BeeNextFunc)) {
	InsertFilterChain("/*", defFunc)
}

func GetUserJWT(ctx *BeeCtx) string {
	return ctx.Input.Data()["user_jwt"].(string)
}
